#include <OgreRoot.h>
#include <OgreSceneManager.h>
#include <OgreCamera.h>
#include <OgreRenderWindow.h>

#include "OgreState.h"
#include "Core.h"


using namespace pong;

void OgreState::load(Core& c) {
    Ogre::Root* const ogreRoot = c.renderer();

    //Create a standard SceneManager
    sceneMan = ogreRoot->createSceneManager(Ogre::ST_GENERIC);

    //Make the camera
    cam = sceneMan->createCamera("camera");
    cam->setNearClipDistance(1);
    //Attach a vieport to the camera from the RenderWindow
    vp = c.renderWindow()->addViewport(cam, 0);

    vp->setBackgroundColour(Ogre::ColourValue::Black);
    cam->setAspectRatio(Ogre::Real(vp->getActualWidth()) /
                        Ogre::Real(vp->getActualHeight()));

}

void OgreState::unload(Core& c) {
    c.renderWindow()->removeViewport(0);
    sceneMan->destroyCamera(cam);
    c.renderer()->destroySceneManager(sceneMan);
}

